/**
 * 登录模块，提供登录相关业务功能
 * 
 * @Date: 2016-1-21
 * @author: Jackson wang
 * @version: 1.0
 * @since: 1.0
 */
define(["jquery", "datagridServ","sysmanMain", "bizProto","btnServ","msgServ","flowInit","buttonEvent","deptUserSelect"],
		function($,datagridServ, sysmanMain, bizProto,btnServ,msgServ,flowInit,buttonEvent,deptUserSelect) {

		'use strict';

		var _typeUrl = '/dictionary/getTree.action',_rootpath,
			item_code_dic_id = 32,
			rootId = 'panel-duties-inquiry',
			edit_window_id='duties-inquiry-win',
			el_width = 300,el_big_width=674,window_width=900,window_height=600
		
		var public_method ={
			
			/**
			 * 初始化新增页面
			 * @param _options.record 列表选中行
			 * @param _options.form 页面form对象
			 */
			initElement:function(_options){
				
			},
			/**
			 * @param _options.record
			 */
			buttonExtends:function(){
				return {'查看详情':private_method.detailInfo}
			},
			closeWindow:function(){
				$('#'+edit_window_id).empty()
				var _moduleConfig = sysmanMain.getCurrentModuConfig();
				_moduleConfig.initParam = {editable:true};
				sysmanMain.setCurrentModuConfig(_moduleConfig);
			},
			/**
			 * @param _options.rootId
			 * @param _options.conditionSelector
			 * @param _options.
			 */
			initList:function(_options){
				private_method.initCondition(_options)
			},
			reCreateField:function(_options){
				private_method.reCreateField(_options)
			},
			rowDblClick:function(index,row){
				private_method.rowDblClick(index,row)
			}
			
		}
		var private_method = {
			//查看详情
			detailInfo:function(e){
				if(window.console){
					console.info('show detail loaded...')
				}
				
				var deptEl = $('#'+edit_window_id + ' #litigant_deptname')
				
				if(deptEl.length>0){
					var deptValue = $(deptEl).textbox('getValue');
					var _param = {sqks:deptValue,over_days_ge:50,sxzt:'在办'}
					var initQueryParams = {condition:_param}
					
					
					sysmanMain.setModuConf('dutiesInfo',{initQueryParams:initQueryParams})
					
					sysmanMain.dutiesInfoSelect()
				}
				
				if(e && e.currentTarget){
					$(e.currentTarget).linkbutton('enable');
				}
				
				
			},
			rowDblClick:function(index,row){
				
				var editWindow = edit_window_id;
				var _param = {}
				var _moduleConfig = sysmanMain.getCurrentModuConfig();
				if(!_moduleConfig){
					_moduleConfig={}
				}
				
				var _param = {
					index:index,
					row:row,
					rootId:rootId,
					editWindow:edit_window_id,
					//moduleConfig:sysmanMain.getCurrentModuConfig(),传入空值，自动取当前模块配置
					url:'/dutiesInquiry/query/editPage.action',
					width:window_width,
					height:window_height
				}
				buttonEvent.doubleClickEdit(_param)
				
			},
			/**
			 * 初始化条件查询框
			 * @param _options.rootId 窗口根节点id
			 * @param _options.conditionSelector 条件框节点选择器
			 */
			initCondition:function(_options){
				if(window.console){
					console.info('recipel init loaded and starting...')
				}
				
				flowInit.initList(_options)
			},
			
			
			/**
			 * @param _options.form		目标对象form
			 */
			reCreateField:function(_options){
				
				var normal_width_param = {width:el_width}
				var big_width_param = $.extend({},{width:el_big_width,multiline:true,height:50})
				var $form = _options.form
				_rootpath = '/'+sysmanMain.getRootPath()
				var fConfig = {
					bizno:$.extend({fieldType:'textbox'},normal_width_param),		
					inquiry_date:$.extend({fieldType:'datebox'},normal_width_param),
					summy_count:$.extend({fieldType:'datebox'},normal_width_param),
					inquiry_reason:$.extend({fieldType:'textbox'},big_width_param),
					litigant_content:$.extend({fieldType:'textbox'},big_width_param),
					decide_content:$.extend({fieldType:'textbox'},big_width_param),
					affirm_content:$.extend({fieldType:'textbox'},big_width_param),
					litigant_name:$.extend(
						{
							fieldType:'textbox',
							onClickButton:function(data){								
								deptUserSelect.openPage({
									userids:'duties-inquiry-win #litigant_id',
									usernames:'duties-inquiry-win #litigant_name',
									deptid:'duties-inquiry-win #litigant_deptid',
									deptname:'duties-inquiry-win #litigant_deptname'
								})								
							}
						},normal_width_param),
						
					inquiry_item:$.extend(
							{fieldType:'combobox'},
							{
								textField:'name',
								valueField:'name',
								url:_rootpath + _typeUrl+'?id=' + item_code_dic_id,
								onSelect:function(record){
									var _item = $(_options.form).find('#inquiry_item_code')
									$(_item).val(record.id)
									
								}
							},
							normal_width_param),
					affirm_result:$.extend(
							{fieldType:'combobox'},
							{
								textField:'name',
								valueField:'name',
								url:_rootpath + _typeUrl+'?id=' + 112,
								onSelect:function(record){
									var _item = $(_options.form).find('#affirm_result_code')
									$(_item).val(record.id)
									
									var $username = $(_options.form).find('#affirm_name')
									var $userid = $(_options.form).find('#affirm_id')
									
									var curUser = sysmanMain.getCurrentUser()
									$($username).textbox('setValue',curUser.name)
									$($userid).val(curUser.id)
								},
								onLoadSuccess:function(){
									if(selectedRecord && selectedRecord.affirm_result_code){
										$(_confirmSelect).combobox('select',selectedRecord.affirm_result_code)									
									}
								}
							},
							normal_width_param)
					
				}
				flowInit.initField({
					fieldConfig:fConfig,
					fieldStatus:_options.data,
					window_id:edit_window_id
				})
			}
		}
			
			return public_method;

		});